package com.jxc.dao.impl;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import com.jxc.dao.TbEmployeeDAO;
import com.jxc.dao.TbEmployeeRoleDAO;
import com.jxc.dao.role;
import com.jxc.dao.TbRoleDAO;
import com.jxc.entity.TbEmployeeRole;
import com.jxc.entity.TbRole;
public class roleImpl implements role{
	
	@Resource private TbRoleDAO tbRoleDAO;
	@Resource private TbEmployeeRoleDAO tbEmployeeRoleDAO;
	private List list = new ArrayList();//这个是数据链表
	@SuppressWarnings("unchecked")
	//role列表
	public List<TbRole> QueryRoleList() {
		
		return this.tbRoleDAO.findAll();
	}
	//role删除
	public  boolean RemoveRole(int id){
	        boolean bool=false;
			try {
				this.tbRoleDAO.delete(id);
				return true;
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return bool;
	}
	//role添加
	public boolean SaveRole(TbRole tbRole)
	{
		boolean bool=false;
		try {
			this.tbRoleDAO.save(tbRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
	//role更新
	public  boolean UpdateRole(TbRole tbRole)
	{
		boolean bool=false;
		try {
			this.tbRoleDAO.attachDirty(tbRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
	public  TbRole QueryRoleByID(Integer ID)
	{
		return this.tbRoleDAO.findById(ID);
	}
	
	public  List QueryRoleListForPage(int start, int limit)//角色列表分页
	{
		return this.tbRoleDAO.findPageAll(start, limit);
	}
	
	public  int QueryRoleTotalRecord()//角色列表总记录
	{
		return this.tbRoleDAO.totalRecord();
	}
	public boolean RoleIsExistByName(String name)
	{
		 boolean bool=false;
			try {
		        list=tbRoleDAO.findByProperty("name", name);
		        if(list.size()>0)
		        {
		        	bool=true;
		        }
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return bool;
	}
	
	public List<TbRole> QueryRoleListByName(String name)//通角色查询列表记录
	{
		return tbRoleDAO.findByProperty("name", name);
	}
	
	public  boolean SaveEmployeeRole(TbEmployeeRole tbEmployeeRole)
	{
		boolean bool=false;
		try {
			this.tbEmployeeRoleDAO.save(tbEmployeeRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
	
	public  boolean RemoveEmployeeRole(TbEmployeeRole tbEmployeeRole)
	{
		boolean bool=false;
		try {
			this.tbEmployeeRoleDAO.delete(tbEmployeeRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
	public  boolean UpdateEmployeeRole(TbEmployeeRole tbEmployeeRole)//角色总记录
	{
		boolean bool=false;
		try {
			this.tbEmployeeRoleDAO.attachDirty(tbEmployeeRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bool;
	}
	
	public  List QueryEmployeeRoleListByUserID(int userID)
	{
		return this.tbEmployeeRoleDAO.findByUserId(userID);
	}
	
	
	public  List QueryRoleListForByWhere(String strWhere)
	{
		return this.tbRoleDAO.findByIdByWhere(strWhere);
	}
	

}
